
#pragma once
#include "raycast.h"

#pragma pack(push, 1)
struct Camera : public Intr
{
    Camera(float4 cam) : Intr(cam) {}
    __device__ __forceinline__ float3 cam2world(int u, int v, float z) const
    {
        // TODO 这里可预先计算fx，fy倒数，然后计算乘法，应该会快一些
        float x = __fdividef(z * (u - cx), fx);
        float y = __fdividef(z * (v - cy), fy);
        return make_float3(x, y, z);
    }
    __device__ __forceinline__ float2 Projector(const float3 &p)
    {
        float2 coo;
        coo.x = __fmaf_rn(fx, __fdividef(p.x, p.z), cx);
        coo.y = __fmaf_rn(fy, __fdividef(p.y, p.z), cy);
        return coo;
    }
};

#pragma pack(pop)

